let url=require("url");
let express=require('express');
let router = express.Router();


router.get('/', function(req, res, next) {
  var str=url.parse(req.url,true).query;  
  var pool = global.POOL;
  var query = async () => {
    var connect = await pool.connect()
    try {
      const result=await connect.query(`select id AS contentid,title,content,posted,deleted,module_name from contents where id = $1 and deleted= $2 `, [str.contentid,false])
      console.log(result.rows[0])
      if(result.rows.length===0){
        res.send({get:'id not defined'})
      }
      else{
        res.send(result.rows[0]);
      }
    } finally {
      connect.release()
    }
  }

  query().catch(e => {
    res.send({get:'error'});
    console.error(e.message, e.stack)});
});

module.exports = router;
